/**
	Glavni razred
	
	@author Gasper
*/

import java.io.Console;
import splash.core.Settings;
import splash.core.Util;
import splash.gui.MainFrame;
import splash.core.logging.Logger;
import splash.core.connection.ConsoleUI;

public class Main
{
        /* Sice this is 'hacked' lite version only one user is present */
	private static final int D_PORT = 42390;
	private static final int SEC_PORT = 31113;
	private static final int D_MAX_CLIENTS = 1;
	private static final String D_PASSWORD = "";
	
	public static void main(String[] args)
	{
		Settings nastavitve;
		Logger log;

                /* Defaults */
		boolean gui = true;
		boolean debug = false;
                /* Output request and response headers */
                boolean verb = false;
		
		log = new Logger();
		
		//konzolni ali grafi�ni vmesnik
		for(String arg : args)
		{
			if(arg.equals("-c"))
				gui = false;
			else if(arg.equals("-d"))
			{
				debug = true;
				//output na zaslon
				log.setStream(System.out);
			}
                        else if(arg.equals("-h"))
			{
				verb = true;
			}
		}
                log.print("################ Program pognan #############");
                log.print("Cas:" + Util.getTimestamp());
		log.print("Nastavitve: ");
		log.print("GUI: " + gui);
		log.print("Debug: " + debug);
		
		if(gui)
		{
                        MainFrame mn = new MainFrame();
                        nastavitve = new Settings(D_MAX_CLIENTS, D_PORT, SEC_PORT, D_PASSWORD, debug, mn, verb);
			mn.main(log, nastavitve);
		}
		else
		{
                        /* Get password from differen source */
                        Console con = System.console();
                        System.out.println("Prosimo vnesite glavno geslo:");
                        char[] pwd = con.readPassword();
                        String pass = new String(pwd);
                        
                        System.out.println("Moc vasega gesla je " + Util.passwordStrength(pass) + ".");
                        
                        nastavitve = new Settings(D_MAX_CLIENTS, D_PORT, SEC_PORT, pass, debug, null, verb);
			new Thread(new ConsoleUI(log, nastavitve, null)).start();
		}
		
                log.print(Util.getTimestamp() + " - Program koncan");
		log.close();

	}
}
